using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class HotkeyTipsPanel : BaseUI
{
    public enum FloatingType
    {
        PressF,
        PressD,
    }
    Dictionary<FloatingType, Transform> m_UIs = new Dictionary<FloatingType, Transform>();
    Dictionary<FloatingType, GameObject> m_BindTarget = new Dictionary<FloatingType, GameObject>();

    float m_FlatingOffset = 20;
    private void Awake()
    {
        m_UIs.Add(FloatingType.PressF, transform.Find("PressF"));
        m_UIs.Add(FloatingType.PressD, transform.Find("PressD"));
    }
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        foreach (var i in m_BindTarget)
        {
            if (m_UIs.ContainsKey(i.Key) && i.Value)
            {
                var screenPoint = Camera.main.WorldToScreenPoint(i.Value.transform.position);

                m_UIs[i.Key].transform.position = screenPoint + new Vector3(0, 60 + Mathf.Sin(Time.time * 3) * m_FlatingOffset, 0);
            }
        }
    }

    public void ShowTip(GameObject onObj, FloatingType type, string title = "")
    {
        if (!m_UIs.ContainsKey(type))
        {
            return;
        }
        m_UIs[type].gameObject.SetActive(true);
        var titleText = m_UIs[type].GetComponentInChildren<TextMeshProUGUI>();
        if (titleText)
            titleText.text = title;
        if (!m_BindTarget.ContainsKey(type))
            m_BindTarget.Add(type, null);
        m_BindTarget[type] = onObj;
    }
    public void HideTip(FloatingType type)
    {
        if (!m_UIs.ContainsKey(type))
        {
            return;
        }
        m_UIs[type].gameObject.SetActive(false);
        if (m_BindTarget.ContainsKey(type))
        {
            m_BindTarget[type] = null;
        }
    }
}
